// OUTDOOR SECTION SCRIPT
//    Section: X = 0, Y = 0

// This is the special encounter script for this town.
// The states INIT_STATE and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 200, 0 = farmer

beginoutdoorscript;

variables;

short i, j, k, fin, choice;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
break;

beginstate START_STATE;
// Starting state of the section, called every turn the party 
// stands inside this section until you change the state.
break;

beginstate 10;
	block_entry(1);
	fin = get_flag(50, 1);
	reset_dialog();
	add_dialog_str(0, "Ahead of you is the path leading away from the land of Llylgamyn.", 0);
	if (fin == 0)
		add_dialog_str(1, "Leaving would leave the amulet unfound and Trebor's quest undone.", 0);
	else
		add_dialog_str(1, "You are finished with the task at hand.", 0);
	add_dialog_choice(0, "Stay here.");
	add_dialog_choice(1, "Leave for other adventures elsewhere.");
	choice = run_dialog(0);
	if (choice == 2) {
		reset_dialog();
		if (fin > 0) {
			i = 1;
			add_dialog_str(0, "You found and defeated the evil wizard Werdna and retrieved the amulet.", 0);
			if (get_flag(50, 2) > 0) {
				add_dialog_str(1, "You hope that with the death of the mad Overlord, the citizens of Llylgamyn can live in peace.", 0);
				add_dialog_str(2, "And that one day, they'll thank you for the effort.", 0);
				i = 3;
			}
			else if (get_flag(50, 3) > 0) {
				add_dialog_str(1, "You have all received the chevron of the Overlord.", 0);
				add_dialog_str(2, "You leave knowing that with the amulet, the Overlord will sink deeper into madness.", 0);
				add_dialog_str(3, "You hope you never have to return to the land of Llylgamyn.", 0);
				i = 4;
			}
			if (get_flag(50, 3) == 0) {
				i = i + 1;
				if (has_item(452)) {
					add_dialog_str(i, "You inspect the amulet that is still in your possession.", 0);
					i = i + 1;
					add_dialog_str(i, "You know, with this, you could rule the world...", 0);
					i = i + 1;
				}
				else {
					add_dialog_str(i, "You are thankful that you lost the amulet knowing it would bring you trouble.", 0);
					i = i + 1;
				}
			}
			add_dialog_str(i, "You congratulate yourselves on the way out of the valley.", 0);
		}
		else {
			if (get_flag(50, 2) == 0) {
				add_dialog_str(0, "You leave the land of Llylgamyn knowing that you weren't strong enough to complete the task.", 0);
				add_dialog_str(1, "One day you think you'll return to quest for the amulet once again.", 0);
			}
			else {
				add_dialog_str(0, "You leave the land of Llylgamyn, after killing it's mad Overlord.", 0);
				add_dialog_str(1, "You left the amulet in the possession of the evil wizard Werdna.", 0);
				add_dialog_str(2, "With it, through time, he will wreak havoc on the citizen's of Llylgamyn and surrounding regions.", 0);
				add_dialog_str(3, "Too bad for them...", 0);
			}
		}
		choice = run_dialog(0);
		end_scenario(fin);
	}
break;

beginstate 11;
	if (get_flag(50, 2) > 0) {
		block_entry(1);
		reset_dialog();
		add_dialog_str(0, "Before you can get close to the farmhouse, several arrows fly out and strike the party.", 0);
		add_dialog_str(1, "You hear a voice sobbing _You bastards, you've kill Trebor._", 0);
		add_dialog_str(2, "There is no way you can get close to the house without getting killed, so you back off.", 0);
		add_dialog_str(3, "Hopefully one day, the citizens will welcome you back knowing you did them a service.", 0);
		add_dialog_choice(0, "OK");
		choice = run_dialog(0);
		i = 0;
		while (i < 4) {
			if (char_ok(i) == TRUE) {
				damage_char(i, get_ran(1, 1, 30), 4);
			}
			i = i + 1;
		}
	}
	else {
		if (get_flag(200, 0) == 0) {
			set_flag(200, 0, 1);
			reset_dialog();
			add_dialog_str(0, "As the party approaches the farmhouse, the farmer and his wife step out on the porch.", 0);
			add_dialog_str(1, "_Howdy_ the farmer cheerily barks at you.", 0);
			add_dialog_str(2, "With that, you enter in a conversation about what you are doing here.", 0);
			add_dialog_str(3, "You feel more than a little queezy with the adoration being expressed for Trebor.", 0);
			add_dialog_str(4, "You wonder if the guy or his wife has seen him recently.", 0);
			add_dialog_str(5, "After more conversation (most of which you struggled not to laugh out loud at), you leave.", 0);
			add_dialog_str(6, "You glance back wondering about the sanity of all here in Llylgamyn.", 0);
			add_dialog_choice(0, "OK");
			choice = run_dialog(0);
		}
		else {
			message_dialog("The farmer and his wife welcome you back exchanging news.", "They still seem to be worshipping Trebor almost insanely.");
		}
	}
break;
